package com.card.hwatt.core;

import java.io.IOException;
import java.util.Date;

import org.apache.commons.lang.time.DateUtils;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;

public class CustomDateDeserializer extends JsonDeserializer<Date> {

	@Override
	public Date deserialize(JsonParser jp, DeserializationContext ctxt)
			throws IOException, JsonProcessingException {
		try {
			String txt = jp.getText();
			return DateUtils.parseDate(txt, new String[] { "yyyy-MM-dd",
					"yyyy-MM-dd HH:mm:ss" });
		} catch (Exception e) {
			return null;
		}
	}
}
